/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GE_RUNTIME_ATTRS_H
#define GE_RUNTIME_ATTRS_H
#include <cstdint>
#include <cstddef>
#include <vector>
#include "graph/tensor.h"
#include "register/any.h"

namespace ge {
using std::vector;
class RuntimeAttrs {
public:
    /**
     * 获取属性
     * @tparam T 属性类型
     * @param index 属性index
     * @return 指向属性的指针
     */
    template <typename T> const T* GetAttrPointer(size_t index) const
    {
        if (index >= values_.size()) {
            return nullptr;
        }
        if (!values_[index].has_value()) {
            return nullptr;
        }
        return any_cast<T>(&values_[index]);
    }
    /**
     * 获取int类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const int64_t* GetInt(const size_t index) const
    {
        return GetAttrPointer<int64_t>(index);
    }
    /**
     * 获取list int类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const vector<int64_t>* GetListInt(const size_t index) const
    {
        return GetAttrPointer<vector<int64_t>>(index);
    }
    /**
     * 获取list int类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const vector<vector<int64_t>>* GetListListInt(const size_t index) const
    {
        return GetAttrPointer<vector<vector<int64_t>>>(index);
    }
    /**
     * 获取string类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const char* GetStr(const size_t index) const
    {
        return (*GetAttrPointer<string>(index)).c_str();
    }
    /**
     * 获取tensor类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const Tensor* GetTensor(const size_t index) const
    {
        return GetAttrPointer<Tensor>(index);
    }
    /**
     * 获取float类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const float* GetFloat(const size_t index) const
    {
        return GetAttrPointer<float>(index);
    }
    /**
     * 获取bool类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const bool* GetBool(const size_t index) const
    {
        return GetAttrPointer<bool>(index);
    }

    /**
     * 获取list_float32类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const vector<float>* GetListFloat(const size_t index) const
    {
        return GetAttrPointer<vector<float>>(index);
    }

    /**
     * 获取list_float32类型属性
     * @param index 属性index
     * @return 指向属性值的指针
     */
    const vector<vector<float>>* GetListListFloat(const size_t index) const
    {
        return GetAttrPointer<vector<vector<float>>>(index);
    }

    /**
     * 获取属性数量
     * @return 属性数量
     */
    size_t GetAttrNum() const
    {
        return values_.size();
    }

    RuntimeAttrs(vector<any>&& values) : values_(std::move(values))
    {
    }

    RuntimeAttrs(const RuntimeAttrs&) = delete;
    RuntimeAttrs(RuntimeAttrs&&) = delete;
    RuntimeAttrs& operator=(const RuntimeAttrs&) = delete;
    RuntimeAttrs& operator=(RuntimeAttrs&&) = delete;

private:
    vector<any> values_;
};
} // namespace ge
#endif // GE_RUNTIME_ATTRS_H
